/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.fd.controller;

import java.util.Collection;
import java.util.List;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xy.lang.domain.Page;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.SaveChecks;
import com.xy.lang.validation.UpdateChecks;
import com.xy.lang.validation.annotation.Validatable;

import com.xy.biz.fd.domain.resp.GetDocumentCodePoolResponse;
import com.xy.biz.fd.domain.req.GetDocumentCodePoolRequest;
import com.xy.biz.fd.domain.req.ListDocumentCodePoolRequest;
import com.xy.biz.fd.domain.req.SaveDocumentCodePoolRequest;
import com.xy.biz.fd.domain.query.DocumentCodePoolQuery;
import com.xy.biz.fd.domain.converter.DocumentCodePoolConverter;
import com.xy.biz.fd.client.DocumentCodePoolClient;
import com.xy.biz.fd.service.DocumentCodePoolService;

/**
 *
 *
 * @author zgy
 * @date 2021-6-11
 */
@Api(tags = "编号池服务")
@Slf4j
@RestController
@RequestMapping("/api/fd/document_code_pool")
public class DocumentCodePoolController implements DocumentCodePoolClient {

    @Autowired
    private DocumentCodePoolService documentCodePoolService;

    @Validatable(groups = {SaveChecks.class})
    @PostMapping(value = "/save_code_pool")
    public Result<? extends Integer> saveDocumentCodePool(@RequestBody SaveDocumentCodePoolRequest request) {
        return documentCodePoolService.saveDocumentCodePool(DocumentCodePoolConverter.toBO(request));
    }

    /*@Validatable(groups = {SaveChecks.class})
    @PostMapping(value = "/save_all")
    public Result<?> saveAllDocumentCodePool(@RequestBody Collection<SaveDocumentCodePoolRequest> collection) {
        documentCodePoolService.saveAllDocumentCodePool(DocumentCodePoolConverter.toBO(collection));
        return Result.success();
    }*/

    @Override
    @Validatable(groups = {UpdateChecks.class})
    @PostMapping(value = "/update_code_pool")
    public Result<? extends Integer> updateDocumentCodePool(@RequestBody SaveDocumentCodePoolRequest request) {
        return documentCodePoolService.updateDocumentCodePool(DocumentCodePoolConverter.toBO(request));
    }

    @Validatable
    @PostMapping(value = "/delete_code_pool")
    public Result<?> deleteDocumentCodePool(@RequestBody GetDocumentCodePoolRequest request) {
        documentCodePoolService.deleteDocumentCodePool(request.getDocumentCodePoolId());
        return Result.success();
    }

    @Override
    @PostMapping(value = "change_code_status")
    public Result<? extends Integer> updateAllDocumentCodePoolByCode(@RequestBody Collection<SaveDocumentCodePoolRequest> collection) {
        return documentCodePoolService.updateAllDocumentCodePoolByCode(DocumentCodePoolConverter.toBO(collection));
    }

    @Validatable
    @PostMapping(value = "/get_code_pool")
    public Result<GetDocumentCodePoolResponse> getDocumentCodePool(@RequestBody GetDocumentCodePoolRequest request) {
        return Result.success(DocumentCodePoolConverter.toResponse(documentCodePoolService.getDocumentCodePool(request.getDocumentCodePoolId())));
    }

   /* @PostMapping(value = "/list_by_ids")
    @Override
    public Result<List<GetDocumentCodePoolResponse>> listDocumentCodePoolById(@RequestBody Collection<Long> collection) {
        return Result.success(DocumentCodePoolConverter.toResponse(documentCodePoolService.listDocumentCodePoolById(collection)));
    }*/

    /*@PostMapping(value = "/list")
    public Result<List<GetDocumentCodePoolResponse>> listDocumentCodePool(@RequestBody ListDocumentCodePoolRequest request) {
        return Result.success(DocumentCodePoolConverter.toResponse(documentCodePoolService.listDocumentCodePool(DocumentCodePoolConverter.toQuery(request))));
    }

    @PostMapping(value = "/count")
    public Result<Integer> countDocumentCodePool(@RequestBody ListDocumentCodePoolRequest request) {
        return Result.success(documentCodePoolService.countDocumentCodePool(DocumentCodePoolConverter.toQuery(request)));
    }

    @PostMapping(value = "/page")
    public Result<Page<GetDocumentCodePoolResponse>> pageDocumentCodePool(@RequestBody ListDocumentCodePoolRequest request) {
        DocumentCodePoolQuery query = DocumentCodePoolConverter.toQuery(request);
        List<GetDocumentCodePoolResponse> list = DocumentCodePoolConverter.toResponse(documentCodePoolService.listDocumentCodePool(query));
        int count = documentCodePoolService.countDocumentCodePool(query);
        return Result.success(new Page<>(list, count));
    }*/

}
